//
//  BFShGoodDetailViewController.m
//  BeautyFood
//
//  Created by apple on 2020/5/1.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THGoodDetailViewController.h"
#import "THGoodCommentViewController.h"
#import "THCustomServiceViewController.h"
@interface THGoodDetailViewController ()
@property(nonatomic, strong) STTools_ImageAdjustView                     *footer_image_view;/**<  */
@property(nonatomic, strong) THGoodDetailModel                     *detailModel;/**<  */
@property(nonatomic, strong) NSMutableArray                     *groupViewArray;/**<  */
@property(nonatomic, strong) STLabel                     *typeLable;/**<  */
@property(nonatomic, strong) STPageControl                     *pageControl;/**< <##> */
@property(nonatomic, strong) UIImageView                     *videoView;/**<  */
@property(nonatomic, strong) STButton                     *videoButton;/**<  */
@property(nonatomic, strong) STTools_PageView                     *page_view;/**<  */
@property(nonatomic, assign) bool                     did_chose;/**<  */
@property(nonatomic, assign) bool                     did_load_image_all;/**<  */
@property(nonatomic, strong) NSMutableArray                     *parm_imageViewArrray;/**<  */
@property(nonatomic, strong) NSMutableArray                     *detail_imageViewArrray;/**<  */
@end

@implementation THGoodDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weakSelf =  self;
    [THHomeDataController stoneobs_fun_get_good_detail:self.g_id  handle:^(THGoodDetailModel * _Nonnull model) {
        self.detailModel = model;
        [self stoneobs_ui_configSubView];
        [self configTableFooter];
        [self config_bootom_view];
    }];
    self.navigationController.navigationBar.hidden = YES;
    self.cus_navgationBar.backgroundColor = UIColor.clearColor;
    [self.cus_navgationBar.rightButton setImage:ST_IMAGE_NAMED(@"分享") forState:UIControlStateNormal];
    [self.cus_navgationBar.leftButton setImage:ST_IMAGE_NAMED(@"返回") forState:UIControlStateNormal];
    [self.cus_navgationBar.rightButton setClicAction:^(UIButton *sender) {
        THShareViewController*vc = THShareViewController.new ;
        vc.good_id = weakSelf.g_id;
        [weakSelf presentViewController:vc animated:NO completion:nil];
    }];
    [self.cus_navgationBar.titleButton setTitleColor:UIColor.clearColor forState:UIControlStateNormal];
    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.height = TMUtils.stoneobs_fun_get_tabBarTop;
    


    // Do any additional setup after loading the view.
}
- (UIImageView*)createVideoViewWithUrl:(NSString*)url{
    
    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, self.page_view.height - 30)];
    [STTools_VideoLoadManger.manger loadVideoCacheWithUrl:url compelet:^(UIImage *cacheImage, NSString *path) {
        stoneobs_ui_imageView.image = cacheImage;
    }];
    stoneobs_ui_imageView.contentMode = UIViewContentModeScaleAspectFill;
    stoneobs_ui_imageView.clipsToBounds = YES;
    stoneobs_ui_imageView.userInteractionEnabled = NO;
    STButton * button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 70, 24)
                                                  title:@"播放"
                                             titleColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                              titleFont:11
                                           cornerRadius:12
                                        backgroundColor:[UIColor.whiteColor colorWithAlphaComponent:0.7]
                                        backgroundImage:nil
                                                  image:[UIImage imageNamed:@"mi_pei_icon_play"]];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    button.centerX = UISCREEN_WIDTH / 2;
    button.centerY = stoneobs_ui_imageView.height / 2;
    [self.view addSubview:button];
    __weak typeof(self) weakSelf =  self;
    [self.videoButton removeFromSuperview];
    self.videoButton = button;
    [button setClicAction:^(UIButton *sender) {
        STTools_VideoPlayViewController * vc =  STTools_VideoPlayViewController.new;
        vc.url = url;
        [weakSelf pushViewController:vc animated:1];
    }];
    return stoneobs_ui_imageView;
    
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    UIView * header = [UIView.alloc initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    __weak typeof(self) weakSelf =  self;
    NSMutableArray * image_aray = NSMutableArray.new;
    for (NSString * deal in self.detailModel.icons.mutableCopy) {
//        NSString *sdeal = [deal stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [image_aray addObject:deal];
        
    }
//    [image_aray addObject:@"http://file2.qishengmeiyi.com/images/WcH3upw0p3EUrzqte59aMwb1BzOYaRQYLbPJAD0Y.mp4"];
    STTools_PageView * page_view = [[STTools_PageView alloc] initWithFrame:CGRectMake(0, 0, STONEOBS_UI_UISCREEN_WIDTH - 0, STONEOBS_UI_UISCREEN_WIDTH)];
    page_view.imageUrlArray = image_aray;
    page_view.animationType = FSPagerViewTransformerTypeNone;
    [page_view setOnSelectedBannerHandle:^(NSInteger index) {
        NSString * name = image_aray[index];
        if ([name containsString:@"mp4"]) {
            STTools_VideoPlayViewController * vc =  STTools_VideoPlayViewController.new;
            vc.url = name;
            [weakSelf pushViewController:vc animated:1];
        }else{
            STTools_WebViewController * webvc =  [STTools_WebViewController.alloc initWithUrl:name];
            webvc.forceTitle = @"图片";
            [weakSelf pushViewController:webvc animated:1];
        }
    }];
    [page_view setScrollDidScroll:^(NSInteger currentIndex) {
        weakSelf.pageControl.currentPage = currentIndex;
        [weakSelf.videoView removeFromSuperview];
        [weakSelf.videoButton removeFromSuperview];
        NSArray * originArray = image_aray;
        NSString * name = originArray[currentIndex];
        if ([name containsString:@"mp4"]) {
            weakSelf.videoView = [weakSelf createVideoViewWithUrl:name];
            [weakSelf.page_view.superview insertSubview:weakSelf.videoView atIndex:0];
            [weakSelf.page_view.superview insertSubview:weakSelf.videoButton atIndex:1];
        }
    }];
    self.page_view = page_view;
    page_view.backgroundColor = UIColor.clearColor;
    [header addSubview:page_view];
    page_view.pagerView.layer.cornerRadius = 0;
    page_view.pagerView.clipsToBounds = YES;
    page_view.autoMoveDuring = 5;
    
    STPageControl * pageControl = [STPageControl.alloc initWithPages:image_aray.count handle:^(NSInteger tag) {
        
    }];
    self.pageControl = pageControl;
    pageControl.currentPageIndicatorTintColor  = STONEOBS_UI_THEME_BACKGROUNDCOLOR;
    pageControl.pageIndicatorTintColor = [STONEOBS_UI_THEME_BACKGROUNDCOLOR colorWithAlphaComponent:0.3];
    pageControl.centerX = STONEOBS_UI_UISCREEN_WIDTH / 2;
    pageControl.bottom = page_view.bottom - 35;
    [header addSubview:pageControl];
    __weak typeof(pageControl) weakpageControl=  pageControl;

    
    
    CGFloat top = page_view.bottom -20;
    
    {{
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30 - 80, 20)
                                                                text:[NSString stringWithFormat:@"￥%@",self.detailModel.cus_selected_spec_price]
                                                           textColor:FlatRed
                                                                font:20
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 10;
        stoneobs_ui_label.attributedText = [stoneobs_ui_label.text stoneobs_fun_st_convertAttributeStringWithKeyWord:@"￥" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];

    }};
    
    {{
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30 - 80, 20)
                                                                text:self.detailModel.name
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:20
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 10;
        

    }};
    

    
    {{
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 20)
                                                                text:self.detailModel.brief
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 20;
    }};
    
    //价格显示
    ({
        for (NSString * title in self.detailModel.tags) {
            STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 20)
                                                                    text:title
                                                               textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                    font:12
                                                             isSizetoFit:NO
                                                           textAlignment:NSTextAlignmentLeft];
            [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
            [header addSubview:stoneobs_ui_label];
            top = stoneobs_ui_label.bottom + 10;
        }
    });
    
    //商品编号
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 20)
                                                                text:[NSString stringWithFormat:@"商品编号:%@",self.detailModel.spu_id]
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 10;
    });
    
    
    ({
        if (self.detailModel.free_postage.floatValue > 0) {
            STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 20)
                                                                    text:[NSString stringWithFormat:@"满%@包邮",self.detailModel.free_postage]
                                                               textColor:FlatRed
                                                                    font:15
                                                             isSizetoFit:NO
                                                           textAlignment:NSTextAlignmentLeft];
            [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
            [header addSubview:stoneobs_ui_label];
            top = stoneobs_ui_label.bottom + 10;
        }else{
            
        }

    });
    
    if (1) {
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 20)
                                                                text:[NSString stringWithFormat:@"赠送积分:%@",self.detailModel.integral]
                                                           textColor:FlatRed
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 10;
    }
    
    ({
        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 10)];
        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
        [header addSubview:stoneobs_ui_line];
        top = stoneobs_ui_line.bottom;
    });
    
    ({
        UIView * whiteView  = [UIView.alloc initWithFrame:CGRectMake(0, top, UISCREEN_WIDTH, 70)];
        whiteView.backgroundColor = self.tableView.backgroundColor;
        [header addSubview:whiteView];
        
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, 60)
                                                                  title:@"规格"
                                                             titleColor:UIColor.blackColor
                                                              titleFont:16
                                                           cornerRadius:10
                                                        backgroundColor:UIColor.whiteColor
                                                        backgroundImage:nil
                                                                  image:nil];
        [whiteView addSubview:stoneobs_ui_button];
        
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
        stoneobs_ui_button.titleLabel.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:16];
        
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 7, 12)];
        stoneobs_ui_imageView.image = [UIImage imageNamed:@"圆角矩形580"];
        [stoneobs_ui_button addSubview:stoneobs_ui_imageView];
        stoneobs_ui_imageView.centerY = stoneobs_ui_button.height / 2;
        stoneobs_ui_imageView.right = stoneobs_ui_button.width - 15;
        stoneobs_ui_imageView.hidden = YES;
        
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(10, 10, UISCREEN_WIDTH - 90, 40)
                                                                text:[NSString stringWithFormat:@"%@ %@",self.detailModel.cus_type_selcted,self.detailModel.cus_selected_spec.name]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentRight];
        [stoneobs_ui_button addSubview:stoneobs_ui_label];
        stoneobs_ui_label.right = stoneobs_ui_button.width - 30;
        self.typeLable = stoneobs_ui_label;

    
        top = whiteView.bottom + 10;
        
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            weakSelf.detailModel.cus_pt_mine_buy = NO;
            [weakSelf stoneobs_action_on_slected_type_button];
        }];
//        if (self.detailModel.specs.count > 1) {
//            stoneobs_ui_imageView.hidden = NO;
//            [stoneobs_ui_button setClicAction:^(UIButton *sender) {
//                [weakSelf stoneobs_action_on_slected_type_button];
//            }];
//        }
 
    });
    

    
    
    ({
        UIView * sheader = [TMUtils stoneobs_fun_titleButtonViewWithTile:@"商品评价" showRightGo:YES handle:^{
            THGoodCommentViewController * vc = THGoodCommentViewController.new;
            vc.detailModel = weakSelf.detailModel;
            [weakSelf pushViewController:vc animated:YES];
        }];
        [header addSubview:sheader];
        sheader.top = top;
        top = sheader.bottom;
    });
    
    ({
        for (NSInteger i = 0; i < self.detailModel.cus_comment.count; i ++) {
            THCommentItemView * view = [[THCommentItemView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
            view.model = self.detailModel.cus_comment[i];
            view.top = top;
            top = view.bottom ;
            
            [header addSubview:view];
        }

    });
    ({
        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 10)];
        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
        [header addSubview:stoneobs_ui_line];
        top = stoneobs_ui_line.bottom;
    });
    
    if (self.detailModel.is_pt) {
        ({
            UIView * sheader = [TMUtils stoneobs_fun_titleButtonViewWithTile:@"拼团详情" showRightGo:NO handle:^{
                
            }];
            [header addSubview:sheader];
            sheader.top = top;
            top = sheader.bottom;
        });
        self.groupViewArray = NSMutableArray.new;
        
        UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, top, UISCREEN_WIDTH, 100)];
        [header addSubview:scrollView];
        scrollView.backgroundColor = UIColor.whiteColor;
        top = scrollView.bottom;
           if (@available(iOS 11.0, *)) {
               scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
           } else {
               
           }
           scrollView.showsHorizontalScrollIndicator = NO;
        CGFloat left = 15;
           for (NSInteger i =0; i < self.detailModel.groups.count; i ++) {
               THGoodDetailModelGourpItemModel * model = self.detailModel.groups[i];
               STButton * contentView = [[STButton alloc] initWithFrame:CGRectMake(left, 10, 70, 90)
                                                                         title:nil
                                                                    titleColor:nil
                                                                     titleFont:0
                                                                  cornerRadius:25
                                                               backgroundColor:nil
                                                               backgroundImage:nil
                                                                         image:nil];
               [scrollView addSubview:contentView];
               left = contentView.right + 15;
               scrollView.contentSize = CGSizeMake(left, 0);
               [self.groupViewArray addObject:contentView];
               [contentView setClicAction:^(UIButton *sender) {
                   weakSelf.detailModel.cus_selected_group = model;
                   
                   for (UIButton * exButton in weakSelf.groupViewArray) {
                       [exButton stbw_setBorderWith:2 borderColor:UIColor.clearColor cornerRadius:4];
                   }
                   [sender stbw_setBorderWith:2 borderColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR cornerRadius:4];
               }];
               if (model == self.detailModel.cus_selected_group) {
                   [contentView stbw_setBorderWith:2 borderColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR cornerRadius:4];
               }
               STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(10, 5, 50, 50)
                                                                         title:nil
                                                                    titleColor:nil
                                                                     titleFont:0
                                                                  cornerRadius:25
                                                               backgroundColor:nil
                                                               backgroundImage:nil
                                                                         image:nil];
               stoneobs_ui_button.userInteractionEnabled = NO;
               [stoneobs_ui_button sd_setImageWithURL:model.user.header_img.mj_url forState:UIControlStateNormal];
               [contentView addSubview:stoneobs_ui_button];
               
               STLabel * titleLabel = [[STLabel alloc] initWithFrame:CGRectMake(0, stoneobs_ui_button.bottom+10, 30+stoneobs_ui_button.width, 20)
                                                                text:[NSString stringWithFormat:@"还差%@人",model.sub]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:10
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentCenter];
               titleLabel.centerX = stoneobs_ui_button.centerX;
               [contentView addSubview:titleLabel];
               

           }
 
    }

    header.height = top;
    header.backgroundColor = UIColor.whiteColor;
    self.tableView.tableHeaderView = header;

}
- (void)configTableFooter{
    __weak typeof(self) weakSelf =  self;
    
    self.parm_imageViewArrray = NSMutableArray.new;
    self.detail_imageViewArrray = NSMutableArray.new;
    
    NSMutableArray * allImages = NSMutableArray.new;
    [allImages addObjectsFromArray:self.detailModel.parameter];
    
    dispatch_group_t group = dispatch_group_create();
    
//    for (NSString * url in self.detailModel.parameter) {
//        dispatch_group_enter(group);
//        [SDWebImageManager.sharedManager loadImageWithURL:url.mj_url options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
//
//        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
//
//            if (image) {
//                CGFloat witdh = UISCREEN_WIDTH;
//                CGFloat height = (image.size.height / image.size.width) * witdh;
//                UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, witdh, height)];
//                imageView.image = image;
//                [self.parm_imageViewArrray addObject:imageView];
//                UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
//                    STTools_WebViewController * webvc =  [STTools_WebViewController.alloc initWithUrl:url];
//                    webvc.forceTitle = @"图片";
//                    [weakSelf pushViewController:webvc animated:1];
//                }];
//                [imageView addGestureRecognizer:tap];
//                imageView.userInteractionEnabled = YES;
//            }
//            dispatch_group_leave(group);
//        }];
//
//    }

    for (NSString * url in self.detailModel.imgs) {
        dispatch_group_enter(group);
        [SDWebImageManager.sharedManager loadImageWithURL:url.mj_url options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
            
        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
            
            if (image) {
                CGFloat witdh = UISCREEN_WIDTH;
                CGFloat height = (image.size.height / image.size.width) * witdh;
                UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, witdh, height)];
                imageView.image = image;
                [self.detail_imageViewArrray addObject:imageView];
                
                UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
                    STTools_WebViewController * webvc =  [STTools_WebViewController.alloc initWithUrl:url];
                    webvc.forceTitle = @"图片";
                    [weakSelf pushViewController:webvc animated:1];
                }];
                [imageView addGestureRecognizer:tap];
                imageView.userInteractionEnabled = YES;
            }
            dispatch_group_leave(group);
        }];
       
    }
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        
        UIView * footer = [[UIView alloc] initWithFrame:CGRectZero];
        footer.backgroundColor = UIColor.whiteColor;
        CGFloat top = 0;
//        ({
//            UIView * sheader = [TMUtils stoneobs_fun_titleButtonViewWithTile:@"商品参数" showRightGo:NO handle:^{
//                
//            }];
//            [footer addSubview:sheader];
//            sheader.top = top;
//            top = sheader.bottom;
//        });
//        for (UIImageView * imageView in self.parm_imageViewArrray) {
//            [footer addSubview:imageView];
//            imageView.top = top;
//            top = imageView.bottom;
//        }
        ({
            UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 5)];
            stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
            [footer addSubview:stoneobs_ui_line];
            top = stoneobs_ui_line.bottom + 20;
        });

        ({
            UIView * sheader = [TMUtils stoneobs_fun_titleButtonViewWithTile:@"图文详情" showRightGo:NO handle:^{
                
            }];
            [footer addSubview:sheader];
            sheader.top = top;
            top = sheader.bottom;
        });
        for (UIImageView * imageView in self.detail_imageViewArrray) {
            [footer addSubview:imageView];
            imageView.top = top;
            top = imageView.bottom;
        }
        
        ({
            UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 5)];
            stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
            [footer addSubview:stoneobs_ui_line];
            top = stoneobs_ui_line.bottom + 20;
        });

        
        footer.height = top;
        self.tableView.tableFooterView = footer;
        if (!self.did_load_image_all) {
            [self configTableFooter];
        }
        self.did_load_image_all = YES;
    });
    
    



    
    
}
- (void)config_bootom_view{

    [[self.view viewWithTag:100001] removeFromSuperview];
    UIView * bootom_view = [[UIView alloc] initWithFrame:CGRectMake(0, TMUtils.stoneobs_fun_get_tabBarTop, STONEOBS_UI_UISCREEN_WIDTH, 80)];
    bootom_view.backgroundColor = UIColor.whiteColor;
    [bootom_view stoneobs_fun_st_showTopShadow];
    bootom_view.tag = 100001;
    [self.view addSubview:bootom_view];
    __weak typeof(self) weakSelf =  self;
    
    NSArray * array = @[@{@"title":@"收藏",@"imageName":@"收藏"},
                        @{@"title":@"客服",@"imageName":@"客服"},
                        @{@"title":@"购物车",@"imageName":@"购物车"}
    ];
    bool selcted = self.detailModel.is_collection;
    if (selcted) {
        array = @[@{@"title":@"已收藏",@"imageName":@"收藏s"},
                            @{@"title":@"客服",@"imageName":@"客服"},
                            @{@"title":@"购物车",@"imageName":@"购物车"}
        ];
        
    }
    NSInteger count = array.count;
    CGFloat buttonWith = 45;

    for (NSInteger i = 0 ;i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        UIColor * color = STONEOBS_UI_SECEND_TEXT_COLOR;
        if ( i == 0 && selcted) {
            color = WH_UICOLOR_FROM_RGBA(0xFF6955);
        }
        
        STTools_MenuControl * menuControl = [[STTools_MenuControl alloc] initWithFrame:CGRectMake(0, 9, buttonWith, 49) imageName:imageName title:title titleColor:color imageHeight:23 lableHeight:17];
        [menuControl setOnSelctedControl:^(STTools_MenuControl *control) {
            
            [weakSelf stoneobs_action_onsetced_menu:title];
        }];
        menuControl.tag = 10000 + i;
        [bootom_view addSubview:menuControl];
        menuControl.left = 10+(i % 4) * buttonWith;

    }
    
    
    
    CGFloat witdh = (STONEOBS_UI_UISCREEN_WIDTH - 40 - (buttonWith * 3)) / 2;
    if (self.detailModel.is_pt) {
        CGFloat cwitdh = (STONEOBS_UI_UISCREEN_WIDTH - 40 - (buttonWith * 3)) / 3;
        CGFloat right = UISCREEN_WIDTH - 10;
        ({
            STButton * stoneobs_ui_car_button = [[STButton alloc] initWithFrame:CGRectMake(15, 0, cwitdh, 40)
                                                                      title:@"加入拼团"
                                                                 titleColor:UIColor.whiteColor
                                                                  titleFont:14
                                                               cornerRadius:20
                                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                            backgroundImage:nil
                                                                      image:nil];
            stoneobs_ui_car_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [bootom_view addSubview:stoneobs_ui_car_button];
            [stoneobs_ui_car_button setClicAction:^(UIButton *sender) {
                weakSelf.detailModel.cus_pt_mine_buy = NO;
                weakSelf.detailModel.is_pt = 1;
                [weakSelf stoneobs_action_onsetced_join_pt];
            }];
            stoneobs_ui_car_button.right = right;
            stoneobs_ui_car_button.centerY = 49/2.0;
            stoneobs_ui_car_button.backgroundColor = [UIColor colorWithGradientStyle:UIGradientStyleLeftToRight withFrame:stoneobs_ui_car_button.bounds andColors:@[WH_UICOLOR_FROM_RGBA(0xFF8B59),WH_UICOLOR_FROM_RGBA(0xFB692A)]];
            right = stoneobs_ui_car_button.left - 5;
        });
        ({
            STButton * stoneobs_ui_car_button = [[STButton alloc] initWithFrame:CGRectMake(15, 0, cwitdh, 40)
                                                                      title:@"创建拼团"
                                                                 titleColor:UIColor.whiteColor
                                                                  titleFont:14
                                                               cornerRadius:20
                                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                            backgroundImage:nil
                                                                      image:nil];
            stoneobs_ui_car_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [bootom_view addSubview:stoneobs_ui_car_button];
            [stoneobs_ui_car_button setClicAction:^(UIButton *sender) {
                weakSelf.detailModel.cus_pt_mine_buy = NO;
                [weakSelf stoneobs_action_onsetced_buy_now];
            }];
            stoneobs_ui_car_button.right = right;
            stoneobs_ui_car_button.centerY = 49/2.0;
            [TMUtils stoneobs_fun_makeViewToThemeGrdualColor:stoneobs_ui_car_button];
            right = stoneobs_ui_car_button.left - 5;
        });
        
        ({
            STButton * stoneobs_ui_car_button = [[STButton alloc] initWithFrame:CGRectMake(15, 0, cwitdh, 40)
                                                                      title:@"单独购买"
                                                                 titleColor:UIColor.whiteColor
                                                                  titleFont:14
                                                               cornerRadius:20
                                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                            backgroundImage:nil
                                                                      image:nil];
            stoneobs_ui_car_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [bootom_view addSubview:stoneobs_ui_car_button];
            [stoneobs_ui_car_button setClicAction:^(UIButton *sender) {
                weakSelf.detailModel.cus_pt_mine_buy = YES;
                [weakSelf stoneobs_action_onsetced_not_join_now];
            }];
            stoneobs_ui_car_button.right = right;
            stoneobs_ui_car_button.centerY = 49/2.0;
            [TMUtils stoneobs_fun_makeViewToThemeGrdualColor:stoneobs_ui_car_button];
            right = stoneobs_ui_car_button.left - 5;
        });
        
        
    }else{
        ({
            STButton * stoneobs_ui_car_button = [[STButton alloc] initWithFrame:CGRectMake(15, 0, witdh, 40)
                                                                      title:@"加入购物车"
                                                                 titleColor:UIColor.whiteColor
                                                                  titleFont:14
                                                               cornerRadius:20
                                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                            backgroundImage:nil
                                                                      image:nil];
            stoneobs_ui_car_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [bootom_view addSubview:stoneobs_ui_car_button];
            [stoneobs_ui_car_button setClicAction:^(UIButton *sender) {
                weakSelf.detailModel.cus_pt_mine_buy = NO;
                [weakSelf stoneobs_action_onsetced_add_car];
            }];
            stoneobs_ui_car_button.left = (buttonWith * 3) + 15;
            stoneobs_ui_car_button.centerY = 49/2.0;
            stoneobs_ui_car_button.backgroundColor = [UIColor colorWithGradientStyle:UIGradientStyleLeftToRight withFrame:stoneobs_ui_car_button.bounds andColors:@[WH_UICOLOR_FROM_RGBA(0xFF8B59),WH_UICOLOR_FROM_RGBA(0xFB692A)]];
        });
        ({
            STButton * stoneobs_ui_car_button = [[STButton alloc] initWithFrame:CGRectMake(15, 0, witdh, 40)
                                                                      title:@"立刻购买"
                                                                 titleColor:UIColor.whiteColor
                                                                  titleFont:14
                                                               cornerRadius:20
                                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                            backgroundImage:nil
                                                                      image:nil];
            stoneobs_ui_car_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [bootom_view addSubview:stoneobs_ui_car_button];
            [stoneobs_ui_car_button setClicAction:^(UIButton *sender) {
                weakSelf.detailModel.cus_pt_mine_buy = NO;
                [weakSelf stoneobs_action_onsetced_buy_now];
            }];
            stoneobs_ui_car_button.right = UISCREEN_WIDTH - 10;
            stoneobs_ui_car_button.centerY = 49/2.0;
            [TMUtils stoneobs_fun_makeViewToThemeGrdualColor:stoneobs_ui_car_button];
        });
    }
    
  

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat change_y = 200.0;
    CGFloat change_postion = 100;
    CGFloat y = scrollView.contentOffset.y;
    CGFloat chazhi = (y-change_postion) / change_y;
    self.cus_navgationBar.backgroundColor = [STONEOBS_UI_THEME_BACKGROUNDCOLOR colorWithAlphaComponent:chazhi];
    [self.cus_navgationBar.titleButton setTitleColor:[UIColor.whiteColor colorWithAlphaComponent:chazhi] forState:UIControlStateNormal];
    
}
#pragma mark --stoneobs Action Method
- (void)stoneobs_action_on_slected_type_button{
    
    THGoodSpecChosedViewController * vc = THGoodSpecChosedViewController.new;
    vc.detailModel = self.detailModel;
    [vc setOnSlectedDidChangeSpecHandle:^{
        [self stoneobs_ui_configSubView];
    }];
    [self presentViewController:vc animated:NO completion:nil];
}
- (void)stoneobs_action_onsetced_menu:(NSString*)title{
    if ([title isEqualToString:@"收藏"]) {
        [THHomeDataController stoneobs_fun_collect_good:self.detailModel.g_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
            self.detailModel.is_collection = YES;
            [self config_bootom_view];
        }];
    }
    if ([title isEqualToString:@"已收藏"]) {
        [THHomeDataController stoneobs_fun_collect_good:self.detailModel.g_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
            self.detailModel.is_collection = NO;
            [self config_bootom_view];
        }];
    }
    
    if ([title isEqualToString:@"客服"]) {
        [BFBaseConfigDataController stoneobs_fun_get_customer_service_with_handle:^(NSString * _Nonnull phone, NSString * _Nonnull wechat) {
            THCustomServiceViewController * vc = THCustomServiceViewController.new;
            vc.phone = phone;
            vc.wechat = wechat;
            [self presentViewController:vc animated:NO completion:nil];
        }];
        
    }
    if ([title isEqualToString:@"购物车"]) {
        [self pushViewController:THShopCarViewController.new animated:1];
    }
}
- (void)stoneobs_action_onsetced_add_car{
    if (!self.did_chose) {
        [self stoneobs_action_on_slected_type_button];
        self.did_chose = YES;
        return;
    }
    
    [THHomeDataController stoneobs_fun_add_car:self.detailModel.g_id num:@(self.detailModel.cus_selected_spec.cus_num).description
                                     type_name:self.detailModel.cus_type_selcted
                                       spec_id:self.detailModel.cus_selected_spec.s_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
        
    }];
}
- (void)stoneobs_action_onsetced_buy_now{
    if (!self.did_chose) {
        [self stoneobs_action_on_slected_type_button];
        self.did_chose = YES;
        return;
    }
    self.detailModel.is_pt = YES;
    
    THCommitOrderViewController * vc = THCommitOrderViewController.new;
    vc.detailModel = self.detailModel;
    vc.is_pt_and_i_create = YES;
    [self pushViewController:vc animated:YES];
}
- (void)stoneobs_action_onsetced_not_join_now{
    if (!self.did_chose) {
        [self stoneobs_action_on_slected_type_button];
        self.did_chose = YES;
        return;
    }
    
    self.detailModel.is_pt = NO;
    THCommitOrderViewController * vc = THCommitOrderViewController.new;
    vc.detailModel = self.detailModel;
    
    [self pushViewController:vc animated:YES];
}

- (void)stoneobs_action_onsetced_join_pt{
    THCommitOrderViewController * vc = THCommitOrderViewController.new;
    vc.detailModel = self.detailModel;
    
    [self pushViewController:vc animated:YES];
    
}

@end

